package com.ldu.houserent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ldu.houserent.entity.Mark;
import com.ldu.houserent.mapper.MarkMapper;
import com.ldu.houserent.service.MarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 收藏service的实现类
 */
@Service
public class MarkServiceImpl implements MarkService {

    @Autowired
    private MarkMapper markMapper;

    //mapper对象
    @Override
    public BaseMapper<Mark> getRepository() {
        return markMapper;
    }

    //获取查询器
    @Override
    public QueryWrapper<Mark> getQueryWrapper(Mark mark) {
        QueryWrapper queryWrapper=new QueryWrapper();
        if (mark!=null){
            if (mark.getUserId()!=null){
                queryWrapper.eq("user_id",mark.getUserId());
            }
            if (mark.getHouseId()!=null){
                queryWrapper.eq("house_id",mark.getHouseId());
            }
        }
        return queryWrapper;
    }

    //获取带参数的查询器
    @Override
    public QueryWrapper<Mark> getQueryWrapper(Map<String, Object> condition) {
        return null;
    }

    //根据用户id和房屋id，查询该用户是否已经收藏过该房屋
    @Override
    public List<Mark> findByUserIdAndHouseId(Long userId, Long houseId) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("house_id",houseId);
        return markMapper.selectList(queryWrapper);
    }
}
